package com.example.qujihai.myapplication;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.view.animation.PathInterpolator;
import android.widget.TextView;

import com.example.qujihai.myapplication.animationUtils.MyInterplator;

public class MainActivity extends AppCompatActivity {

    TextView mytext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mytext = (TextView) findViewById(R.id.hello);
    }

    public void startAnimation(View view) {
        moveLinely();
    }

    private void moveLinely() {
        final ValueAnimator animator = ValueAnimator.ofFloat(100);
        animator.setDuration(1000);
//        animator.setInterpolator(new MyInterplator());
        PathInterpolator myPlator = new PathInterpolator(0.25f,1f,0.75f,1f);
        animator.setInterpolator(myPlator);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float y = (Float) animation.getAnimatedValue();
                mytext.setTranslationX(y);

            }
        });
//        animator.addListener(new Animator.AnimatorListener() {
//            @Override
//            public void onAnimationStart(Animator animation) {
//
//            }
//
//            @Override
//            public void onAnimationEnd(Animator animation) {
//                mytext.setTranslationX((float)animator.getAnimatedValue());
//            }
//
//            @Override
//            public void onAnimationCancel(Animator animation) {
//
//            }
//
//            @Override
//            public void onAnimationRepeat(Animator animation) {
//
//            }
//        });
        animator.start();
    }

    @Override
    protected void onStop() {
        super.onStop();
//        Intent intent = new Intent(MainActivity.this,LockActivity.class);
//        startActivity(intent);
    }
}
